import React,{Component} from 'react'
import './index.css'
import {getNovalDetail} from '../../api'

class Paper extends Component{
    constructor(props){
        super(props)  
        this.state = {
            link: props.location.state.text,
            Text: {}
        }
    }
    go() {
        this.props.history.go(-1)
    } 
    componentDidMount(){ 
        getNovalDetail(this.state.link)
        .then(res =>{
            this.setState({
                Text: res.data.chapter
            })        
        })
      
    }
    render(){
        return(
            <div className='app-paper-box'>
                <header>
                    <a onClick={this.go.bind(this)}><i className='iconfont iconfanhui'>返回</i></a>
                </header>   
               <main>
                    <h4>{ this.state.Text? this.state.Text.title:''}</h4>
                    <div className='content'> 

                        {this.state.Text?
                            <div className='txt' dangerouslySetInnerHTML={{__html: String(this.state.Text.cpContent).replace(/[\r\n]+/g, '<br/>')  }} ></div> 
                       :''}
                      
                    </div>                    
               </main>                
            </div>
        )
    }
}

export default Paper